# -*- coding: UTF-8 -*-

import logging
from celery import task
from celery.utils.log import get_task_logger
from django.core.mail import send_mail

import os
from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')


app = Celery('mysite')

# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


@app.task(bind=True)
def celery_send_email(self, title, content, emailfrom, maillist):
    print('Request: {0!r}'.format(self.request))
    send_mail(title, content, emailfrom, maillist, fail_silently=False)   


'''
@task  
def celery_send_email(title, content, email, maillist):
    print("celery send mail")
    send_mail(title, content, 'labadmin_lte@hytera.com', maillist, fail_silently=False)   
    
    
@task
def celery_timer(x, y):
    logger = get_task_logger(__name__)
    logger.info('func start  ----------------->')
    logger.info('application:%s', "celery_timer")
    logger.info('func end -------------------->')
    print(x + y)
    return(x + y)


@task
def celery_schedule(x, y):
    logger = get_task_logger(__name__)
    logger.info('func start  ----------------->')
    logger.info('application:%s', "celery_schedule")
    logger.info('func end -------------------->')
    print(x * y)
    return(x * y)
'''
